{% extends 'base.html' %}
{% block self_head_css_js %}
    <script src="/static/layer/layer.js"></script>
    <script src="/static/js/jquery.bootstrap-duallistbox.js"></script>
    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap-duallistbox.css">
{% endblock %}
{% block content %}

    <script>
        window.onload=init;
        function init() {
            var box = document.getElementById("delivery");
            box.className="active";
            var box = document.getElementById("delivery_list");
            box.className="active";
        }
    </script>

  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
    </section>

    <!-- Main content -->

    <section class="content">

      <!-- Default box -->
      <div class="box">
        <div class="box-header with-border">
        </div>
        <div class="box-body">
        {% if project_id %}
            <form action="{% url 'delivery_edit' project_id %}" method="post">
        {% else %}
            <form action="{% url 'delivery_add' %}" method="post">
        {% endif %}
        {% csrf_token %}
{#        {{ form.as_p }}#}
        {% for field in form %}
            <div class="fieldWrapper">
                {{ field.errors }}
                {% if field.html_name == "auth" %}
                    {{ field.label_tag }} {{ field }}
                    <a href="#" onclick="return popWin()"><li class="btn btn-success" ><b>添加认证</b></li></a>
                {% else %}
                    {{ field.label_tag }} {{ field }}
                {% endif %}
            </div>
        {% endfor %}
        <p></p>
        <input type="submit" class="btn btn-primary" style="width: 60pt" value="保存">&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="{% url 'delivery_list' %}"><li style="width: 60pt" class="btn btn-primary" value="">返回</li></a><br>
          </form>
        </div>
        <!-- /.box-body -->
        <div class="box-footer">
          <i class="fa fa-info-circle"></i> 请勿重复添加条目
        </div>
        <!-- /.box-footer-->
      </div>
      <!-- /.box -->
    </section>
    {#用于接收appowner_base.html中layui子层的传值#}
    <input id="handle_status" value="" hidden="hidden">
    <input id="new_auth_id" value="" hidden="hidden">
    <input id="new_auth_name" value="" hidden="hidden">
  </div>
    <script>
        var demo1 = $('select[name="serverList"]').bootstrapDualListbox({
              nonSelectedListLabel: '可选择服务器',
              selectedListLabel: '已选择服务器',
              preserveSelectionOnMove: 'moved',
              moveOnSelect: false,
        });
    </script>
<script>
function popWin(){
  layer.open({
      type: 2,
      title: '项目列表',
      area: ['700px', '500px'],
      shadeClose: true, //点击遮罩关闭
      content: ['/appconf/authinfo/add/mini/'],
      end:function(){
            var handle_status = $("#handle_status").val();
            if ( handle_status == '1' ) {
                layer.msg('添加成功！',{
                    icon: 1,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                },function(){
                    var new_auth_id = $("#new_auth_id").val();
                    var new_auth_name = $("#new_auth_name").val();
                    $('#id_auth').append("<option value="+new_auth_id+" selected='selected'>"+new_auth_name+"</option>");
                });
            } else if ( handle_status == '2' ) {
                layer.msg('添加失败！',{
                    icon: 2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                },function(){

                });
            }
      }
  });
}
</script>
{% endblock %}